package com.example.tests;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.util.logging.Logger;
//import static org.testng.Assert.*;
import org.testng.annotations.Test;

import com.example.fw.GroupDataGenerator;
import com.example.fw.Groups;

public class GroupCreationTests extends TestBase {
	
	//make logger
	private Logger log = Logger.getLogger("GroupCreationTests");
	
	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class)
	public void testValidGroupCanBeCreated(GroupObject validGroup) throws Exception {
		log.info("testValidGroupCanBeCreated start");
		Groups oldList = app.getGroupHelper().getGroups();
		log.info("oldList = " + oldList);
		// action
		log.info("validGroup = " + validGroup);
		app.getGroupHelper().createGroup(validGroup);
		// verification
		Groups newList = app.getGroupHelper().getGroups();
		log.info("newList = " + newList);
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
		//verifyGroupAdded(oldList, validGroup, newList);
		log.info("testValidGroupCanBeCreated end");
	}

	//private void verifyGroupAdded(Set<GroupObject> oldList,
			//GroupObject validGroup, Set<GroupObject> newList) {
		//assertEquals(newList.size(), oldList.size()+1);
		//assertThat(newList.size(), equalTo(oldList.size()+1));
		//assertThat(newList, equalTo(oldList));		
	//}

	//@Test
	public void testGroupWithEmptyDataCanBeCreated() throws Exception {
		GroupObject emptyDataGroup = new GroupObject().
				setName("").setHeader("").setFooter("");
		Groups oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(emptyDataGroup);
		Groups newList = app.getGroupHelper().getGroups();
		//verifyGroupAdded(oldList, emptyDataGroup, newList);
		assertThat(newList, equalTo(oldList.withAdded(emptyDataGroup)));
	}
}

